//
//  ProductDetailFooterView.m
//  MeterMart
//
//  Created by ENERGY on 2018/9/24.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ShareView.h"

@interface ShareView()

@end

@implementation ShareView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.alpha = 0;
        UIButton * bgBtn = [[UIButton alloc] initWithFrame:frame];
        [bgBtn setBackgroundColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75]];
        [bgBtn addTarget:self action:@selector(bgBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:bgBtn];
        
        [self setUpViews];
    }
    return self;
}

- (void)setUpViews{
    //白色背景
    UIView * whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    //分享标题
    UILabel * titleLab = [[UILabel alloc] init];
    titleLab.text = @"分享到";
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.font = DEF_FontSize_16;
    [whiteView addSubview:titleLab];
    //关闭按钮
    UIButton * closeBtn = [[UIButton alloc] init];
    [closeBtn setImage:[UIImage imageNamed:@"cross"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:closeBtn];
    //分割线
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = getColor(@"fdfdfe");
    [whiteView addSubview:lineView];
    //分享好友按钮
    UIButton * friendBtn = [[UIButton alloc] init];
    [friendBtn addTarget:self action:@selector(friendBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [friendBtn setImage:[UIImage imageNamed:@"weixin"] forState:UIControlStateNormal];
    [whiteView addSubview:friendBtn];
    //朋友圈按钮
    UIButton * circleBtn = [[UIButton alloc] init];
    [circleBtn setImage:[UIImage imageNamed:@"weChatCircle"] forState:UIControlStateNormal];
    [circleBtn addTarget:self action:@selector(circleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:circleBtn];
    //标题
    UILabel * friendTitleLab = [[UILabel alloc] init];
    friendTitleLab.textAlignment = NSTextAlignmentCenter;
    friendTitleLab.text = @"微信好友";
    friendTitleLab.font = DEF_FontSize_14;
    [whiteView addSubview:friendTitleLab];
    //标题
    UILabel * circleTitleLab = [[UILabel alloc] init];
    circleTitleLab.textAlignment = NSTextAlignmentCenter;
    circleTitleLab.text = @"朋友圈";
    circleTitleLab.font = DEF_FontSize_14;
    [whiteView addSubview:circleTitleLab];
    //masonry
    __weak typeof (self)weakSelf = self;
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf);
        make.height.mas_offset(215/WIDTH_6_SCALE);
    }];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(whiteView);
        make.height.mas_offset(61/WIDTH_6_SCALE);
    }];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(whiteView.mas_right).mas_offset(-17/WIDTH_6_SCALE);
        make.centerY.equalTo(titleLab.mas_centerY);
        make.width.height.mas_offset(26/WIDTH_6_SCALE);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(whiteView);
        make.top.equalTo(titleLab.mas_bottom);
        make.height.mas_offset(1/WIDTH_6_SCALE);
    }];
    [friendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(whiteView.mas_centerX).mas_offset(-(115 / 2)/WIDTH_6_SCALE);
        make.top.equalTo(lineView.mas_bottom).mas_offset(33/WIDTH_6_SCALE);
        make.width.height.mas_offset(49/WIDTH_6_SCALE);
    }];
    [circleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.centerY.width.equalTo(friendBtn);
        make.left.equalTo(whiteView.mas_centerX).mas_offset((115 / 2)/WIDTH_6_SCALE);
    }];
    [friendTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(friendBtn.mas_bottom).mas_offset(15/WIDTH_6_SCALE);
        make.centerX.equalTo(friendBtn.mas_centerX);
    }];
    [circleTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(circleBtn.mas_bottom).mas_offset(15/WIDTH_6_SCALE);
        make.centerX.equalTo(circleBtn.mas_centerX);
    }];
}
#pragma mark - action
- (void)showView{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}
- (void)disappearView{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)closeBtnClick:(UIButton *)sender{
    [self disappearView];
}
- (void)bgBtnClick:(UIButton *)sender{
    [self disappearView];
}
- (void)friendBtnClick:(UIButton *)sender{
    if (self.friendBtnClickBlock) {
        self.friendBtnClickBlock();
        [self disappearView];
    }
}
- (void)circleBtnClick:(UIButton *)sender{
    if (self.circleBtnClickBlock) {
        self.circleBtnClickBlock();
        [self disappearView];
    }
}
@end
